﻿using System.Security.Principal;
using System.Web;
using System.Web.Security;

namespace System.Web.Core
{
    public class UserIdentity : IIdentity
    {
        private string name;
        private string authenticationType;

        public UserIdentity(string name, string authenticationType)
        {
            this.name = name;
            this.authenticationType = authenticationType;
        }

        #region IIdentity 成员

        public string Name
        {
            get
            {
                return name;
            }
        }

        public string AuthenticationType
        {
            get
            {
                return authenticationType;
            }
        }

        public bool IsAuthenticated
        {
            get
            {
                HttpCookie formsCookie = HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName];
                if (formsCookie != null)
                {
                    return FormsAuthentication.Decrypt(formsCookie.Value).Name == Name;
                }
                return false;
            }
        }

        #endregion
    }
}